package com.lizhi.menu.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lizhi.menu.Dto.CommodityCommentDto;
import com.lizhi.menu.Dto.IdListDto;
import com.lizhi.menu.common.response.Result;
import com.lizhi.menu.domain.CommodityComment;
import com.lizhi.menu.service.ICommodityCommentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * 商品评论Controller
 *
 * @author lizhi
 * @date 2023-05-18
 */
@RestController
@RequestMapping("/system/comment")
@RequiredArgsConstructor
@Api(tags = "商品评论管理")
public class CommodityCommentController {
    private final ICommodityCommentService commodityCommentService;

    /**
     * 查询商品评论列表
     */
    @GetMapping("/list")
    @ApiOperation("查询商品评论列表")
    public Result<Page<CommodityComment>> list(CommodityCommentDto dto) {
        return Result.ok(commodityCommentService.selectCommodityCommentList(dto));
    }

    /**
     * 查询商品评论列表
     */
    @GetMapping("/my")
    @ApiOperation("查询我的商品评论列表")
    public Result<Page<CommodityComment>> my(CommodityCommentDto dto) {
        return Result.ok(commodityCommentService.selectCommodityCommentList(dto));
    }

    /**
     * 获取商品评论详细信息
     */
    @GetMapping(value = "/{id}")
    @ApiOperation("获取商品评论详细信息")
    public Result<CommodityComment> getInfo(@PathVariable("id") String id) {
        return Result.ok(commodityCommentService.selectCommodityCommentById(id));
    }

    /**
     * 新增商品评论
     */
    @PostMapping
    @ApiOperation("新增商品评论")
    public Result<Void> add(@RequestBody CommodityComment commodityComment) {
        commodityCommentService.insertCommodityComment(commodityComment);
        return Result.ok();
    }

    /**
     * 修改商品评论
     */
    @PutMapping
    @ApiOperation("修改商品评论")
    public Result<Void> edit(@RequestBody CommodityComment commodityComment) {
        commodityCommentService.updateCommodityComment(commodityComment);
        return Result.ok();
    }

    /**
     * 删除商品评论
     */
    @DeleteMapping("/remove")
    @ApiOperation("删除商品评论")
    public Result<Void> remove(@RequestBody IdListDto ids) {
        commodityCommentService.remove(ids.getIdList());
        return Result.ok();
    }

    /**
     * 删除商品评论
     */
    @DeleteMapping("/{id}")
    @ApiOperation("删除商品评论")
    public Result<Void> remove(@PathVariable String ids) {
        commodityCommentService.remove(ids);
        return Result.ok();
    }
}
